Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Empty Messages #82

Conversation

dezren39
Copy link
Contributor

@dezren39 dezren39 commented Oct 31, 2023

resolves #78

This PR handles empty messages, so that you can use 'just' structured logging while using the text formatter, by skipping the message block.

This pr also aligns all the cases to 'add a space when you need one for this loop' instead of some being that way and others being 'add a space because there will be a next loop'.

An impact to non-text logger, if you provide empty message through message parameter no message is sent. I think if you sent a 'msg' key with an empty string that would still end up in the file.

I gitignored .vscode .history and go.work, sometimes they are needed but they get accidentally committed randomly so it made sense to me to ignore them until there is an active file to be committed for those.

I added 3 new tests, and didn't make any new tests fail,,, except that I have some tests that don't work for me already. #81 was opened for that. Maybe that's my issue? I didn't look into it too much when main branch also didn't succeed.

@dezren39 dezren39 marked this pull request as draft October 31, 2023 05:28
@dezren39
Copy link
Contributor Author

dezren39 commented Oct 31, 2023

My tests all pass but I want to sub this in a couple places and actually 'see' it then I'll re-open. But it's ready for review and I can just delete any parts you don't like. :-) 👍

@dezren39
Copy link
Contributor Author

i have confirmed, at least in 2 small utilities, that this behaves as expected and as the tests describe.
before
image
after
image

@dezren39 dezren39 marked this pull request as ready for review October 31, 2023 20:48
Copy link

codecov bot commented Oct 31, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (e5a733b) 77.63% compared to head (4a1dfd9) 77.95%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #82      +/-   ##
==========================================
+ Coverage   77.63%   77.95%   +0.31%     
==========================================
  Files          10       10              
  Lines         635      644       +9     
==========================================
+ Hits          493      502       +9     
  Misses        128      128              
  Partials       14       14              
Files Coverage Δ
logger.go 85.22% <100.00%> (ø)
text.go 62.29% <88.46%> (+1.95%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dezren39
Copy link
Contributor Author

reviewed, i think this is ok. coverage is still 'up' and the lines that are 'missed' are the same as the rest of the cases, just for timestamp. i expect getting timestamp without level or message or kv is unlikely to occur that often and would take a little setup to even test.

Comment on lines +157 to +159
if !firstKey {
l.b.WriteByte(' ')
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps put this in a helper function writeSpace(bool)

@aymanbagabas
Copy link
Member

Thanks for the PR @dezren39. Some comments, looks good otherwise :)

@aymanbagabas aymanbagabas merged commit 5e84160 into charmbracelet:main Oct 31, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow only structured log output
2 participants